package com.learner.common.util;

public class CodeMsg {
    private int code;
    private String msg;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /*服务端异常*/
    public static CodeMsg SUCCESS = new CodeMsg(200, "SUCCESS");
    public static CodeMsg SERVER_ERROR = new CodeMsg(100, "系统异常：%s");
    public static CodeMsg BIND_ERROR = new CodeMsg(101, "(绑定异常)参数校验异常：%s");
    public static CodeMsg SESSION_ERROR = new CodeMsg(102, "没有SESSION！");
    public static CodeMsg REQUEST_ERROR = new CodeMsg(103, "非法请求！");
    public static CodeMsg ID_ERROR = new CodeMsg(104, "找不到此id值！");


    private CodeMsg() {
    }

    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /* 不定参的构造函数*/
    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }
}
/*https://www.cnblogs.com/loaderman/p/10333835.html*/